<template>
	<view class="page-container back-grey-light">
		<!-- 列表 -->
		<view v-if="list0.length" class="pall-base">
			<view v-for="(item, index) in list0" :key="index" class="mb-l">
				<my-postcard :post="item" @clickPraise="mypostPraiseHandle" :index="index"></my-postcard>
			</view>
			<u-loadmore :status="loadStatus" />
		</view>
		<view v-else class="col-box center pcol-lg">
			<image src="/static/icon/nodata.png" style="width: 400rpx;height: 400rpx;"></image>
			<text class="s24 grey-light">还没有点赞的帖子~</text>
		</view>
	</view>
</template>

<script>
	import mixinPost from "@/common/mixin_post.js"
	import { mapState,mapMutations } from "vuex"
	export default {
		mixins: [mixinPost],
		data() {
			return {
				pageType: 2, // 首页-类型为0 我的帖子-类型为1 我的点赞-类型为2
				type: 0
			};
		},
		// 定义局部分享
		// 1.发送给朋友
		onShareAppMessage(res) {
			// console.log(res)
			if (res.from == 'button') {
				let index = Number(res.target.id.split('_')[1])
				let list = this[`list${this.type}`]
				let post = list[index]
				let type = post.video?'video':'image'
				return {
					title: post.description,
					path: `/pages/subPackage/post/post_${type}/post_${type}?id=${post.id}`,
					imageUrl: type=='video'?post.coverImage:this.getArrImage(post)[0],
				}
			} else {
				return {
					title: '校园服务喵小朋',
					path: this.getSharePath(),
					imageUrl: '/static/icon/logo.jpg',
				}
			}
		},
		// 2.分享到朋友圈
		onShareTimeline(res) {
			if (res.from == 'button') {
				let index = Number(res.target.id.split('_')[1])
				let list = this[`list${this.type}`]
				let post = list[index]
				let type = post.video?'video':'image'
				return {
					title: post.description,
					path: `/pages/subPackage/post/post_${type}/post_${type}?id=${post.id}`,
					imageUrl: type=='video'?post.coverImage:this.getArrImage(post)[0],
				}
			} else {
				return {
					title: '校园服务喵小朋',
					path: this.getSharePath(),
					imageUrl: '/static/icon/logo.jpg',
				}
			}
		},
		onLoad() {
			this.getList(0)
		},
		methods: {
			...mapMutations('m_user', ['updateBackPraise']),
			
			// 点赞-我的点赞使用
			mypostPraiseHandle(id) {
				this.$api.PostPraise({
					worldId: id
				}).then(res => {
					console.log('postPraise-success', res)
					if (res.data.code == 200) {
						this.list0.forEach((curr, index) => {
							if (curr.id == id) {
								this.list0.splice(index, 1)
							}
						})
						this.updateBackPraise({
							id: id,
							praiseStatus: 0
						})
					} else {
						uni.showToast({
							icon: 'none',
							title: res.data.msg
						})
					}
				}).catch(err => {
					console.log('postPraise-fail', err)
				})
			},
		},
	}
</script>

<style lang="scss">

</style>
